package com.ta.gulimall.auth.service.impl;

import cn.hutool.core.lang.TypeReference;
import com.ta.gulimall.auth.feign.MemberFeignService;
import com.ta.gulimall.auth.service.LoginService;
import com.ta.gulimall.auth.view.vo.UserLoginVo;
import com.ta.gulimall.common.constant.AuthConstant;
import com.ta.gulimall.common.utils.system.R;
import com.ta.gulimall.common.view.vo.MemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    MemberFeignService memberFeignService;

    @Override
    public void login(UserLoginVo vo, HttpSession session) {
        R result = memberFeignService.login(vo);
        if (!result.getCode().equals("0")) {
            throw new RuntimeException(result.getMsg());
        }

        MemberVo memberVo = result.getData(new TypeReference<MemberVo>() {});
        session.setAttribute(AuthConstant.LOGIN_USER, memberVo);
    }
}
